STAT
Section: MINTLIB LIBRARY FUNCTIONS
(3)
Updated: 3 March 1993
Index
Return to Main Contents
NAME
stat, lstat, fstat - get file status
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int stat(const char *path, struct stat *buf);
int lstat(const char *path, struct stat *buf);
int fstat(int fd, struct stat *buf);
DESCRIPTION
stat obtains information about the file named by path.
Read, write or execute permission of the named file is not
required, but all directories listed in the path name leading
to the file must be searchable.
lstat is like stat except in the cases where the named
file is a symbolic link, in which case lstat returns
information about the link, while stat returns information
about the file the link references.
fstat obtains the same information about an open file
referenced by the the file descriptor, such as would be
returned by an creat, open, dup, fcntl or pipe call.
buf is a pointer to a stat structure into which information
is placed concerning the file. The stat structure is defined
in <sys/stat.h> and contains the following fields of interest:
struct stat
{
u_short st_mode; /* file mode */
ino_t st_ino; /* the file serial number */
dev_t st_dev; /* device file resides on */
short st_rdev; /* the device identifier */
short st_nlink; /* number of hard links to the file */
uid_t st_uid; /* user ID of the owner */
gid_t st_gid; /* group ID of the owner */
off_t st_size; /* total size of the file, in bytes */
off_t st_blksize; /* preferred blocksize for system I/O */
off_t st_blocks; /* actual number of blocks allocated */
time_t st_mtime; /* file last modify time */
time_t st_atime; /* file last access time */
time_t st_ctime; /* file last status change time */
short st_attr; /* file attributes */
... /* various fields reserved for MiNT */
};
The following masks are available in <sys/stat.h> to test the
st_mode field in the stat structure:
#define S_IFMT 0170000 /* type of file */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
#define S_IFBLK 0060000 /* block special */
#define S_IFREG 0100000 /* regular file */
#define S_IFIFO 0120000 /* FIFO special */
#define S_IMEM 0140000 /* shared memory (?) */
#define S_IFLNK 0160000 /* symbolic link */
#define S_ISUID 04000 /* set-uid on execution */
#define S_ISGID 02000 /* set-gid on execution */
#define S_ISVTX 01000 /* save swapped text */
The following masks are available in <sys/stat.h> to test the
st_attr field in the stat structure:
#define S_IRUSR 0400 /* readable by user */
#define S_IWUSR 0200 /* writeable by user */
#define S_IXUSR 0100 /* executable by user */
#define S_IRGRP 0040 /* readable by group */
#define S_IWGRP 0020 /* writable by group */
#define S_IXGRP 0010 /* executable by group */
#define S_IROTH 0004 /* readable by others */
#define S_IWOTH 0002 /* writable by others */
#define S_IXOTH 0001 /* executable by others */
RETURN VALUES
0 on success.
-1 on failure; errno is set to indicate the error.
SEE ALSO
chmod(3),
chown(3),
Fcntl(2),
Fxattr(2)
NOTE
When MiNT is not active, these calls are emulated under TOS.
The TOS implemenation of fstat in particular is pretty bogus.
You are advised to read the source code of stat.c if you want
to make use of other than the most basic attributes under
TOS emulation.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- SEE ALSO
-
- NOTE
-
This document was created by
man2html,
using the manual pages.
Time: 11:15:07 GMT, June 22, 2025